package com.LeeCode;

/**
 * 有效单词
 */

public class Code3136 {
    public static void main(String[] args) {
        String word = "@ab3";
        System.out.println(new Code3136().isValid(word));
    }

    public boolean isValid(String word) {
        String num = "0123456789", vowels = "aeiouAEIOU";
        int countNum = 0, countVowels = 0, other = 0;
        char[] chars = word.toCharArray();
        for (char c : chars) {
            if (vowels.indexOf(c) != -1) {
                countVowels++;
            } else if (num.indexOf(c) != -1) {
                countNum++;
            } else if ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
                other++;
            } else {
                return false;
            }
        }
        if (countVowels + countNum + other < 3 || countVowels == 0 || other == 0) {
            return false;
        }
        return true;
    }

    public boolean isValid1(String word) {
        if (word.length() < 3) {
            return false;
        }
        boolean[] f = new boolean[2];
        for (char c : word.toCharArray()) {
            if (Character.isAlphabetic(c)) {
                c = Character.toLowerCase(c);
                f[c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ? 1 : 0] = true;
            } else if (!Character.isDigit(c)) {
                return false;
            }
        }
        return f[0] && f[1];
    }
}
